package net.goutalk.glcs.config;


import net.goutalk.glcs.common.xss.XssFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.DispatcherType;
import java.util.HashMap;
import java.util.Map;

/**
 * Filter配置
 * 用于Xss过滤
 *
 * @author tanyujie
 */
@Configuration
public class FilterConfig {

    @Bean
    public FilterRegistrationBean<XssFilter> xssFilterRegistration() {
        FilterRegistrationBean<XssFilter> registration = new FilterRegistrationBean<>();
        registration.setDispatcherTypes(DispatcherType.REQUEST);
        registration.setFilter(new XssFilter());
        registration.addUrlPatterns("/*");
        registration.setName("xssFilter");
        registration.setOrder(Integer.MAX_VALUE);

        Map<String,String> initParameters = new HashMap<>();
        //设置xxs 忽略地址
        initParameters.put("excludes","/magic/*,/magic-api/*");

        registration.setInitParameters(initParameters);
        return registration;
    }
}
